from picshell.ui.Context import Context
from wx._misc import ToolTip
import wx
class ConfigView :
     def __init__(self,parent):
        
        self.configPanel = wx.Panel(parent, -1)
        configSizer  = wx.FlexGridSizer()
        configSizer.SetCols(2)
        self.configPanel.SetSizer(configSizer)
        
        #Compiler
        self.compiler = wx.TextCtrl(self.configPanel,-1,Context.compiler,size=(600,-1))
        self.compiler.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Compiler : "),0,0)
        configSizer.Add(self.compiler,0,0)
        #options
        self.options = wx.TextCtrl(self.configPanel,-1,Context.compilerOptions,size=(600,-1))
        self.options.SetToolTip(ToolTip("Compilers options like -Wno-all etc... use space separartor"))
        self.options.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Options : "),0,0)
        configSizer.Add(self.options,0,0)
        # libpath
        self.libpath = wx.TextCtrl(self.configPanel,-1,Context.libpath,size=(600,-1))
        self.libpath.SetToolTip(ToolTip("use ; to separe paths"))
        self.libpath.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Libraries paths: "),0,0)
        configSizer.Add(self.libpath,0,0)

        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        
        
        #programer
        self.programmer = wx.TextCtrl(self.configPanel,-1,Context.programmer,size=(600,-1))
        self.programmer.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Programmer : "),0,0)
        configSizer.Add(self.programmer,0,0)
        #programer options
        self.programmerOptions = wx.TextCtrl(self.configPanel,-1,Context.programmerOptions,size=(600,-1))
        self.programmerOptions.SetToolTip(ToolTip("Programer options (use token %jal for jal_filename, %asm for asm_filename, %hex for hex_filename)"))
        self.programmerOptions.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Options : "),0,0)
        configSizer.Add(self.programmerOptions,0,0)
        
        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        
        # default open dir
        self.defaultOpenPath = wx.TextCtrl(self.configPanel,-1,Context.sourcepath,size=(600,-1))
        self.defaultOpenPath.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Default open dir : "),0,0)
        configSizer.Add(self.defaultOpenPath,0,0)
        
        
        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        configSizer.Add(wx.StaticText(self.configPanel,-1,""),0,0)
        
        self.devicesPath = wx.TextCtrl(self.configPanel,-1,Context.devicesPath,size=(600,-1))
        self.devicesPath.SetFont(wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL))
        configSizer.Add(wx.StaticText(self.configPanel,-1,"Devices path : "),0,0)
        configSizer.Add(self.devicesPath,0,0)
        
     
     def getView(self):
        return self.configPanel
    
     def OnStoreConfig(self,event):
        Context.compiler = self.compiler.GetValue()
        Context.compilerOptions = self.options.GetValue()
        Context.libpath = self.libpath.GetValue()
        Context.sourcepath = self.defaultOpenPath.GetValue()
        Context.programmer = self.programmer.GetValue()
        Context.programmerOptions = self.programmerOptions.GetValue()
        Context.devicesPath = self.devicesPath.GetValue()
        
        
        Context.save("config.txt")
        event.Skip()
